home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Skunkware 5
/
Skunkware 5.iso
/
src
/
X11
/
tclMotif-1.4
/
tests
/
text.test
< prev
next >
Wrap
Text File
|
1995-06-29
|
7KB
|
293 lines
if {[string compare test [info procs test]] == 1} then \
{source defs}
# set VERBOSE 1
# set INTERACTIVE 1
proc no-changeCB {doit} {
upvar 1 $doit d
set d false
}
proc allcaps {ptr length} {
upvar 1 $ptr p
upvar 1 $length l
if {$l == 0} return
set upper [string toupper $p]
set p $upper
}
#############
# starts here
#############
xtAppInitialize -class Text
. setValues -allowShellResize true
# XtText does not have a natural size, but doesn't like
# zero width, so let a label set a >0 width
xmRowColumn .textrc managed
xmLabel .textrc.label managed
xmText .textrc.t1 managed \
-columns 40
. realizeWidget
##################################
# Manipulating text by resources #
##################################
test text-1.1 {setting and getting text} {
.textrc.t1 setValues -value "The rain in Spain"
.textrc.t1 getValues -value v
set v
} {The rain in Spain}
################################
# Manipulating text by actions #
################################
test text-2.1 {appending text by insert-string} {
.textrc.t1 callActionProc end-of-file()
.textrc.t1 callActionProc {insert-string(" falls mainly")}
.textrc.t1 getValues -value v
set v
} {The rain in Spain falls mainly}
test text-2.2 {deleting text by delete-previous-character} {
.textrc.t1 callActionProc delete-previous-character()
.textrc.t1 callActionProc delete-previous-character()
.textrc.t1 getValues -value v
set v
} {The rain in Spain falls main}
test test-2.3 {inserting text by self-insert} {
.textrc.t1 setValues -value ""
.textrc.t1 callActionProc self-insert() \
-type KeyPress \
-keysym T
.textrc.t1 callActionProc self-insert() \
-type KeyPress \
-keysym h
.textrc.t1 callActionProc self-insert() \
-type KeyPress \
-keysym space
.textrc.t1 callActionProc self-insert() \
-type KeyPress \
-keysym 9
.textrc.t1 getValues -value v
set v
} {Th 9}
#############################
# modification verification #
#############################
############
# no changes
############
test text-3.1 {turn off every change in modifyVerify callback} {
.textrc.t1 setValues -value "The rain in Spain"
.textrc.t1 modifyVerifyCallback {no-changeCB %doit}
.textrc.t1 callActionProc {insert-string(" falls mainly")}
.textrc.t1 getValues -value v
set v
} {The rain in Spain}
####################
# capitalize changes
####################
.textrc.t1 destroyWidget
xmText .textrc.t2 managed \
-columns 40
test text-3.2 {change text in modifyVerify callback} {
.textrc.t2 setValues -value "The rain in Spain"
.textrc.t2 callActionProc end-of-file()
.textrc.t2 modifyVerifyCallback {allcaps %ptr %length}
.textrc.t2 callActionProc {insert-string(" FalLs mAInlY")}
.textrc.t2 getValues -value v
set v
} {The rain in Spain FALLS MAINLY}
#####################################
# setting and getting text by methods
#####################################
.textrc.t2 destroyWidget
xmText .textrc.t3 managed \
-columns 40
test text-4.1 {set and get text} {
.textrc.t3 setString "hello world"
.textrc.t3 getString
} {hello world}
if {$XmVersion >= 1002} {
test text-4.2 {get a substring} {
set found [.textrc.t3 getSubstring 2 3 value]
if {$found == "succeeded"} {
set result $value
} else {set result $found}
set result
} {llo}
}
####################################
# getting and setting editable state
####################################
test text-5.1 {set and get editable state} {
.textrc.t3 setEditable false
.textrc.t3 getEditable
} {false}
test text-5.2 {set and get editable state} {
.textrc.t3 setEditable true
.textrc.t3 getEditable
} {true}
########################################
# getting and setting insertion position
########################################
test text-6.1 {getting and setting insertion position} {
.textrc.t3 setInsertionPosition 5
.textrc.t3 getInsertionPosition
} {5}
test text-6.2 {getting last position} {
.textrc.t3 setString "hello porkpie hat"
.textrc.t3 getLastPosition
} {17}
#################
# finding strings
#################
.textrc.t3 setString "hello world"
if {$XmVersion >= 1002} {
test text-7.1 {search forward for string} {
.textrc.t3 findString 1 wor forward position
set position
} {6}
test text-7.2 {search backward for string} {
.textrc.t3 findString 10 wor backward position
set position
} {6}
test text-7.3 {search for non-existent string} {
.textrc.t3 findString 1 universe forward position
} {false}
}
############################
# manipulating parts of text
############################
test text-8.1 {insert text} {
.textrc.t3 setString "abcdefgh"
.textrc.t3 insert 3 PQRST
.textrc.t3 getString
} {abcPQRSTdefgh}
test text-8.2 {replace text} {
.textrc.t3 replace 3 8 IJKL
.textrc.t3 getString
} {abcIJKLdefgh}
#########################
# scroll and top position
#########################
test text-9.1 {scroll and top position} {
.textrc.t3 setValues -editMode multi_line_edit
.textrc.t3 setString "one\ntwo\nthree"
.textrc.t3 scroll 2
.textrc.t3 getTopCharacter
} {8}
test text-9.2 {set top character} {
.textrc.t3 setTopCharacter 5
.textrc.t3 getTopCharacter
} {4}
test text-9.3 {show position} {
.textrc.t3 setValues -autoShowCursorPosition true
.textrc.t3 showPosition 2
.textrc.t3 getInsertionPosition
} {0}
##################
# multiple sources
##################
test text-10.1 {two sources} {
.textrc.t3 destroyWidget
xmRowColumn .textrc.rc managed
xmText .textrc.rc.text managed
xmText .textrc.rc.text2 managed
.textrc.rc.text setString abcdefgh
.textrc.rc.text2 setSource .textrc.rc.text 0 0
.textrc.rc.text2 getString
} {abcdefgh}
.textrc.rc destroyWidget
###################
# primary selection
###################
xmText .textrc.t4 managed
test text-11.1 {managing the primary selection} {
.textrc.t4 setString "hello world"
.textrc.t4 setSelection 2 7
.textrc.t4 getSelection
} {llo w}
test text-11.2 {locating primary selection} {
.textrc.t4 getSelectionPosition left right
set result "$left $right"
set result
} {2 7}
test text-11.3 {copy and paste primary selection} {
.textrc.t4 copy
.textrc.t4 setInsertionPosition 1
.textrc.t4 paste
.textrc.t4 getString
} {hllo wello world}
test text-11.4 {cut and paste the primary selection} {
.textrc.t4 setString "hello world"
.textrc.t4 setSelection 2 7
.textrc.t4 cut
.textrc.t4 setInsertionPosition 0
.textrc.t4 paste
.textrc.t4 getString
} {llo wheorld}
#############
# Finish up #
#############
if { ! $INTERACTIVE} {
.textrc.label destroyWidget
.textrc.t4 destroyWidget
.textrc destroyWidget
} else {
. mainLoop
}